<!-- <fieldset>
<legend>操作选项</legend>
{if auth("add")}
<button data-modal='{:url("add")}?type=add' data-title="添加部门" class='layui-btn layui-btn-sm layui-btn-primary'>添加部门</button>
{/if}

</fieldset> -->
<fieldset>


    <legend></legend>

    <form id="singcms-form" class="layui-form layui-form-pane form-search" action="{:request()->url()}" onsubmit="return false" method="get" autocomplete="off">
     <div class="layui-form-item layui-inline">
         
    <button data-modal='{:url("add")}?type=add' data-title="添加部门" class='layui-btn layui-btn-sm layui-btn-normal'>添加部门</button>

    </div>
        <div class="layui-form-item layui-inline margin-left-20">
            <label class="layui-form-label">部门名称</label>
            <div class="layui-input-inline">
                <input name="dept_name" value="{$Think.get.dept_name|default=''}" placeholder="请输入部门名称" class="layui-input">
            </div>
        </div>

		{if $userinfo['db1']['authorize'] == 1 || $userinfo['db1']['authorize'] == 8}
		 <div class="layui-form-item layui-inline">
		    <label class="layui-form-label">所属公司</label>
            <div class="layui-input-inline">
                <input name="name" value="{$Think.get.name|default=''}" placeholder="请输入公司名称" class="layui-input">
            </div>

		</div>
		 {/if}


<!--         <div class="layui-form-item layui-inline">
            <label class="layui-form-label">部门状态</label>
            <div class="layui-input-inline">
                <select class="layui-select" name="status">
                    {foreach [''=>'-- 全部状态 --','0'=>'禁用','1'=>'正常'] as $k=>$v}
                    {eq name='Think.get.status' value='$k.""'}
                    <option selected value="{$k}">{$v}</option>
                    {else}
                    <option value="{$k}">{$v}</option>
                    {/eq}
                    {/foreach}
                </select>
            </div>
        </div> -->

<!--          <div class="layui-form-item layui-inline">
            <label class="layui-form-label">添加时间</label>
            <div class="layui-input-inline">
        		  <input type="text" class="layui-input" id="create_at_first" name="create_at_first" value="{$Think.get.create_at_first|default=''}"  placeholder="请选择添加时间">			 

            </div>
          <div class="layui-form-mid">—</div>
        	   <div class="layui-input-inline">
        	<input type="text" class="layui-input" id="create_at_last" name="create_at_last" value="{$Think.get.create_at_last|default=''}"  placeholder="请选择添加时间">
        	</div>
        </div> -->
 <input type="hidden" name="true_spm" value="m-57-58-62">
       <!--  <div class="layui-form-item layui-inline">
            <button class="layui-btn layui-btn-primary search-btn" data-modal="{:url('company/Department/index')}" data-value='type="search"'><i class="layui-icon">&#xe615;</i>搜 索</button> -->
           <div class="layui-form-item layui-inline">
 <button class="layui-btn layui-btn-primary search-btn"><i class="layui-icon">&#xe615;</i>搜 索</button>
</div>
<!-- <button class="layui-btn layui-btn-primary " data-modal="{:request()->url()}?type='search'"><i class="layui-icon">&#xe615;</i>搜 索</button> -->

        <!-- </div> -->
                <!-- <option value="">-- 搜索员工姓名 --</option> -->
              <!--   </select> -->
    </form>

</fieldset>
<script>form.render()</script>
<script>


    layui.use(['laydate','table','util'], function(){
                var SCOPE = {
        'save_url' : "{:url('company/department/index')}",
        'jump_url' : "{:url('company/department/index')}",
    
    };
      var laydate = layui.laydate;
      var table = layui.table;
      var util = layui.util;
      //执行一个laydate实例
      laydate.render({
        elem: '#create_at_first' //指定元素
      });
       laydate.render({
        elem: '#create_at_last' //指定元素
      });

    $('.search-btn').on('click',function(){
        return 
        console.log('TEST GN LEON')
        var data = $("#singcms-form").serializeArray();
        postData = {};
        $(data).each(function(i) {
            postData[this.name]= this.value;
        });
        console.log(postData)
        postData['ajax'] = 'ajax'
        url = SCOPE.save_url;
        jump_url = SCOPE.jump_url;
        $.post(url, postData, function(result) {
            console.log(result)
            if (result.code == 200) {
                $('#dept-table').html('')
            //重新渲染表格数据-------ocde bgen----------
              table.render({
                elem: '#dept-table',
                data: result.data,
                page:true, //开启分页
                cellMinWidth: 100 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                  ,
                done: function (res, curr, count) {
                  $("table").css("width", "100%");
                },
                cols: [[
                {field: 'id', title: '序号', width:'20%', sort: false, fixed: 'left'},
                {field: 'dept_name', title: '部门名称', width:'20%', sort: false, fixed: 'left'},
                {field: 'name', title: '所属公司', width:'20%', sort: false, fixed: 'left'},
                {field: 'status', title: '使用状态', width:'10%', sort: false, fixed: 'left', templet:function(e){
                    if(e.status==1){
                        return '已启用'
                    }
                    if(e.status==0){
                        return '已禁用'
                    }
                }},
                {field: 'createtime', title: '添加时间', width:'20%', sort: false, fixed: 'left', templet:function(e){
                    return util.toDateString(e.createtime * 1000, "yyyy年MM月dd日 HH:mm:ss")
                }},
                {field: '操作选项', title: '操作选项', width:'20%', sort: false, fixed: 'left',toolbar:"#choiceitem"},
                  ]]
              });
                //成功
                // return dialog.success(result.message, jump_url);
            } else if (result.code == 400) {
                // 失败
                // return dialog.error(result.message);
            }
        }, "JSON");

    })

    });
</script>
<script>

</script>
<script type="text/html" id="choiceitem">
  {if auth("edit")}
                <a data-dbclick class="layui-btn layui-btn-sm" data-title="编辑部门信息" data-modal=''>编 辑</a>
                {/if}

</script>